package models

import "encoding/json"

const (
	Ok                  = 200 //成功
	BadRequest          = 400 //请求失败
	Unauthorized        = 401 //验证失败
	InternalServerError = 500 //服务器内部错误

	ServerErr = "服务器异常，请联系管理员！"
)

//返回结果结构
//Code  错误码
//Msg   返回信息
//Date  返回数据
type Result struct {
	Code int
	Msg  string
	Data interface{}
}

func SetResult(code int, msg string, date interface{}) ([]byte, error) {
	model := &Result{code, msg, date}
	res, err := json.Marshal(model)
	return res, err
}

func GetFalatResult() []byte {
	model := &Result{500, "服务器内部错误", ""}
	res, _ := json.Marshal(model)
	return res
}

func GetErrorResult(msg string) []byte {
	model := &Result{500, msg, ""}
	res, _ := json.Marshal(model)
	return res
}
